userinfo_path = 'WoniuATMusers.txt'
#主页面导航
wel_t1="欢迎来到WoniuATM"
opt_t2="请选择操作菜单"
opt_opts="1.注册 2.登录 3.退卡"
#记录登录错误次数
login_error_count = 0
tip = wel_t1.center(50,'*')+'\n'+ opt_t2.center(47,'*') + '\n' + opt_opts.center(48,'*')
def main_meau_print():
    print(tip)
#登录后业务菜单-----------------------------------------------------------------------------------------------
wel_login="恭喜登录蜗牛银行"
tip_login="请选择操作菜单"
opt_login="1.查询 2.取款 3.存款 4.转账 5.流水 6.返回 7.退卡"
login_tip = wel_login.center(50,'*')+'\n'+ tip_login.center(51,'*') + '\n' + opt_login.center(44,'*')
def login_meau_print():
    print(login_tip)
    
def start_menu(option):
    '''
       构建开始菜单
       @param
       @return
        
    '''
    main_meau_print()
    if option!= '':
        option = option
    else:
        option = input('请输入你的操作选项:')
    if option == '1':
        from services.UserService import reg
        reg()
    if option == '2':
        from services.UserService import login
        login()
    if option == '3':
        exit('谢谢,欢迎下次光临')
        
        
        
#构建登录后业务菜单---------------------------------------------------------------------

def main_menu(option):
    login_meau_print()
    if option == '':
        option = input('请输入你的操作选项:')
    else:
        option = option
    if option == '1':#查询
        from services.AccountService import query
        query()
        main_menu('')
    elif option == '2': # 取款
        from services.AccountService import withdraw
        from services.UserService import login_user_id
        from services.AccountService import check_number
        from services.AccountService import deposite
        money = input('请输入取款金额:')
        if check_number(money):
            from services.AccountService import can_withdraw
            if can_withdraw(money, login_user_id):
                withdraw(login_user_id,'取款',money)
            else:
                print('余额不足')
                main_menu('3')  # 去存款
        else:
            print('请输入正确的金额')
            main_menu('2')
        main_menu('')
    elif option == '3': # 存款
        from services.AccountService import deposite
        money = input('请输入存款金额')
        from services.AccountService import check_number
        if check_number(money):
            from services.UserService import login_user_id
            deposite(login_user_id,'存款',money)
        else:
            print('请输入正确的金额')
            main_menu('3')
        main_menu('')
    elif option == '4': # 转账
        from services.AccountService import transfer
        transfer()
        main_menu('')
    elif option == '5': # 流水
        from services.AccountService import history
        history()
        main_menu('')
    elif option == '6': # 返回
        main_menu('')
    elif option == '7': # 退卡
        exit('欢迎下次光临')
    else:
        exit('暂无该选项')
        
# python的默认入口函数

if __name__ == "__main__":
    start_menu('')
        
